﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataObjects.Interface.Sales;
using BusinessObjects.Sales;
using DataObjects.AdoNet;

namespace DataObjects.SqlServer.Sales
{
    public class SqlServerGeneralLedgerDao : IGeneralLedgerDao
    {
        public void InsertGeneralLedger(GeneralLedger generalLedger)
        {
            string sql = "Insert_GeneralLedger";

            generalLedger.GeneralLedgerID = Db.Insert(sql, true, Take(generalLedger));
        }

        public void DeleteGeneralLedgerByRefId(GeneralLedger generalLedger)
        {
            string sql = "Proc_Delete_GeneralLedger_ByRefID";

            object[] parms = {  "@RefID", generalLedger.RefID,
                                "@RefNo", generalLedger.RefNo};

            Db.Update(sql, true, parms);
        }

        private object[] Take(GeneralLedger generalLedger)
        {
            return new object[]  
            {
                "GeneralLedgerID",generalLedger.GeneralLedgerID,
                "RefID",generalLedger.RefID,
                "RefDetailID",generalLedger.RefDetailID,
                "RefType",generalLedger.RefType,
                "RefNo",generalLedger.RefNo,
                "RefDate",generalLedger.RefDate,
                "PostedDate",generalLedger.PostedDate,
                "CurrencyID",generalLedger.CurrencyID,
                "AccountingObjectID",generalLedger.AccountingObjectID,
                "DescriptionMaster",generalLedger.DescriptionMaster,
                "DescriptionDetail",generalLedger.DescriptionDetail,
                "Amount",generalLedger.Amount,
                "RestaurantID",generalLedger.RestaurantID,
            };
        }
    }
}
